package com.cai.handle;

import com.cai.common.result.ResultVO;
import com.cai.ex.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
 * @Title: GlobalException
 * @Author RuoLi
 * @Package com.cai.handle
 * @Date 2024/1/12 15:31
 * @description: 全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class GlobalException {
    public GlobalException() {
        log.debug("创建了【GlobalException】对象，全局异常处理");
    }

    @ExceptionHandler(ServiceException.class)
    public ResultVO handlerServerException(ServiceException serverException){
        log.error("ServerException】，异常信息为：{}",serverException.getMessage());
        return ResultVO.fail(serverException.getMessage());
    }
}
